package com.pengcheng.taskapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.model.BankListItemModel;
import com.pengcheng.taskapplication.model.WalletModel;
import com.pengcheng.taskapplication.mvp.view.widget.CircleImageView;
import com.pengcheng.taskapplication.util.HideUtil;

import org.w3c.dom.Text;

import java.util.List;

public class WalletBankAdapter extends BaseAdapter {

	Context context;
	LayoutInflater inflater;
	List<BankListItemModel> bankVos;
	int last_item;
	private int selectedPosition = -1;
	public WalletBankAdapter(Context context, List<BankListItemModel> bankVos){
		this.context = context;
		this.bankVos = bankVos;
		inflater= LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return bankVos.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return bankVos.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder  holder = null;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.activity_wallet_bank_list_item_layout, null);
			holder = new ViewHolder();
			holder.tv_bank_name=(TextView) convertView.findViewById(R.id.tv_bank_name);
			holder.tv_bank_num=(TextView)convertView.findViewById(R.id.tv_bank_num);
			holder.ll_bg=(LinearLayout)convertView.findViewById(R.id.ll_bg);
			convertView.setTag(holder);
		}
		else{
			holder=(ViewHolder)convertView.getTag();
		}

		BankListItemModel model= bankVos.get(position);
		//holder.tv_bank_num.setText(HideUtil.hideCardNo(model.getBankaccountnumber()));
		String code=model.getBankaccountnumber();
		holder.tv_bank_num.setText(code.substring(code.length()-4,code.length()));
		holder.tv_bank_name.setText(model.getBankname());
		if(position%2==0){
			holder.ll_bg.setBackgroundResource(R.drawable.bank_bg);
		}else{
			holder.ll_bg.setBackgroundResource(R.drawable.bank_bg_other);
		}

		return convertView;
	}

	public static class ViewHolder{
		public TextView tv_bank_num;
		public TextView tv_bank_name;
		public LinearLayout ll_bg;

	}

	public void setSelectedPosition(int position) {
		selectedPosition = position;
	}

}
